<?php
class NewsLetterAdminForm extends Form
{
	function __construct()
	{				
		Form::Form('NewsLetterForm');
	}
	
	function draw()
	{
		global $display;
		
		
		$keyword=Url::get('keyword');
		$display->add('keyword',$keyword);
		
		$display->add('export_link',	Url::build_current(array('cmd'=>'export')));
			
		$where='1';
		
		if($keyword!='')
		$where.=' AND email LIKE "%'.$keyword.'%"';
		
		$total_item	=	DB::count('news_letter_email',$where);
		
		$limit='';
		
		$item_per_page 	= 40;
		$page_no 		= (int)Url::get('page_no');
		
		
		$pagging=AZPagging::paging_list($limit,$total_item,$item_per_page,10);
		
		$re = DB::query('SELECT * FROM news_letter_email WHERE '.$where.' ORDER BY id '.$limit);
		
		$news_letter_emails = array();
		$i=0;
		
		
		
		if($page_no<=0) $page_no = 1;
		
		if($re)
		{
			while($item = mysql_fetch_assoc($re))
			{
				$item['time_add'] 	=  date('H:i',$item['time_add']).' ngày '.date('d/m/Y',$item['time_add']).'<br />Cách đây '.AZLib::duration_time($item['time_add']);
				$item['delete'] 	=  AZLib::buttonDel(Url::build_current(array('cmd'=>'delete','id'=>$item['id'])),'style/images/admin/delete.gif','Loại bỏ Email này khỏi danh sách!');
				
				
				$i++;
				$item['i'] 	=  $i+($page_no-1)*$item_per_page;
				
				
				$news_letter_emails[$item['id']] = $item;
			}
		}
			
		$display->add('pagging',$pagging);
		$display->add('news_letter_emails',$news_letter_emails);
		$display->add('count',$total_item);
		
		$this->beginForm();
		$display->output("NewsLetterAdmin");
		$this->endForm();
	}
}
?>